<?php echo $this->render('link/header.phtml') ?>
//常用变量初始化
var menuCheckUrl=baseUrl+"/link/servercheck/type/check";
var menuCheckExistUrl=baseUrl+"/link/servercheck/type/exist";
var module="linkcheck";
var gridTitle="链接信息检测";
var dataId="link_id";
var selectLength=5;
var link = Ext.data.Record.create([
           {name: 'link_id', type: 'int'},
           {name: 'link_site_id', type: 'string'},
		   {name: 'link_linktype_id', type: 'string'},
           {name: 'link_keyword_id',type:'string'},
           {name: 'link_address', type: 'string'},
           {name:'link_pr'},
           {name:'link_home_pr'},
           {name: 'link_client_id', type: 'string'},
           {name:'link_ischeck',type:'string'},
           {name:'link_isgoogle'},
           {name:'link_isexist'},
           {name:'link_ischeck'},
           {name:'link_google_cache'},
           {name:'link_isinfo'},
           {name:'keyword_name'},
           {name:'keyword_link'},
           {name:'keyword_pr'}
      ]);


var ds=new Ext.data.Store({
							  proxy:new Ext.data.HttpProxy({
									url:baseUrl+'/link/serverlink/type/getAll'
									}),
							  reader:new Ext.data.JsonReader({
									root:'results',
									totalProperty:'total',
									id:'link_id'
									},link)
	});
    		 
//定义列模型
var cm=new Ext.grid.ColumnModel([	
							new Ext.grid.CheckboxSelectionModel(),
                            {header:'链接ID',dataIndex:'link_id',width:50,hidden:true},														
                            {header:'关键字',dataIndex:'keyword_name',width:100},														
                            {header:'Target Link',dataIndex:'keyword_link',width:100},														
                            {header:'TR(PR值)',dataIndex:'keyword_pr',width:150},
							{header:'Inbound Link',dataIndex:'link_address',width:250,renderer:show_link},						
                            {header:'InLink(PR)',dataIndex:'link_pr',width:60},
                            {header:'InLink(域名PR)',dataIndex:'link_home_pr',width:60},
                            {header:'Google收录',dataIndex:'link_isgoogle',width:50,renderer:show_check_status},						
                            {header:'是否存在',dataIndex:'link_isexist',width:50,renderer:show_check_status},
                           /* {header:'Google缓存更新时间',dataIndex:'link_google_cache',width:200},*/
                            {header:'检测状态',dataIndex:'link_isinfo',width:70,renderer:show_check_status}						
	]);
cm.defaultSortable = true; 



//定义工具栏								 
var tb=new Ext.Toolbar({
							items:[

                                         {
                                            id:'menuCheck'+ExtId,
											text:'检测选中',
                                            iconCls:'icn-search',
											handler:menuCheckSelect
											},{
                                            iconCls:'icn-view',
                                            id:'menuCheck'+ExtId,
											text:'检测存在链接',
											handler:menuCheckExist
											},{
                                            iconCls:'icn-contacts-new',
											text:'检测已检测链接',
                                            handler:menuCheckChecked
											},{
                                            iconCls:'icn-snipshot',
											text:'检测未检测链接',
                                            handler:menuCheckNoCheck
											},new Ext.Button({
                                            text:'按链接类型',
                                            menu:{
                                            items:[{text:'发布链接',handler:menuLinkIsAdd},
                                            		{text:'友情链接',handler:menuLinkIsFriend},
                                                    {text:'购买链接',handler:menuLinkIsBuy}
                                            ]
                                            }
                                            }),"-",{
                                            text:'清除查询',
                                            handler:menuClearSearch
                                            },{xtype:'tbfill'},{
                                            text:'检测选中链接是否存在',
                                            handler:menuCheckSelectedExist
                                            }
								 ]
	});			
 
 
function menuLinkIsAdd(){
if(typeof(ds.baseParams.where)=='undefined'){
	var base=(ds.baseParams.where.indexOf('link_linktype')<0)?" and "+ds.baseParams.where:"";
	ds.baseParams.where="link_linktype_id=2"+base;
}
else{
	ds.baseParams.where="link_linktype_id=2";
}
ds.reload();
}

 
function menuLinkIsFriend(){
if(typeof(ds.baseParams.where)=='undefined'){
	var base=(ds.baseParams.where.indexOf('link_linktype')<0)?" and "+ds.baseParams.where:"";
	ds.baseParams.where="link_linktype_id=4"+base;
}
else{
	ds.baseParams.where="link_linktype_id=4";
}
ds.reload();
}

 
function menuLinkIsBuy(){
if(typeof(ds.baseParams.where)=='undefined'){
	var base=(ds.baseParams.where.indexOf('link_linktype')<0)?" and "+ds.baseParams.where:"";
	ds.baseParams.where="link_linktype_id=3"+base;
}
else{
	ds.baseParams.where="link_linktype_id=3";
} 
ds.reload();
}

function menuClearSearch(){
ds.baseParams.where='';
ds.reload();
}

 
function menuCheckExist(){
ds.baseParams.where="link_isexist=1";
ds.reload();
}

function menuCheckChecked(){
ds.baseParams.where="link_isinfo=1";
ds.reload();
}

function menuCheckNoCheck(){
ds.baseParams.where="link_isinfo=0";
ds.reload();
}

function menuCheckSelect(){
	var selectRows=grid.getSelectionModel().getSelections();												
												if(selectRows.length==0){
													Ext.MessageBox.alert('提示','请选择一条数据');
													}
												else{		
													var message="";
                                                    if(selectRows.length>selectLength){
                                                    Ext.MessageBox.alert('提示','一次查询数据请不要超过'+selectLength+'条');
                                                    return;
                                                    }
													for(var i=0;i<selectRows.length;i++){
														if(i!=0){
															message+=",";
															}
														message+=selectRows[i].get(dataId);
														}  
                                                 var _gridBody=Ext.getCmp('grid_'+ExtId).body;   
                                                 _gridBody.mask('查询数据中...');
                                                 Ext.Ajax.request({
																	 url:menuCheckUrl,
																	 params:{id:message},																																		 																	success:function(response,option){
																var temp=Ext.util.JSON.decode(response.responseText);                                                  				_gridBody.unmask();
																ds.load({params:{start:0,limit:30}});
																grid.render();
																		 },
																	failure:function(response,option){
                                                                    _gridBody.unmask();
																		var temp=Ext.util.JSON.decode(response.responseText);	                                              						Ext.MessageBox.alert('waring',temp.msg);
																		}
																	 });
													}
}


function menuCheckSelectedExist(){
var selectRows=grid.getSelectionModel().getSelections();												
												if(selectRows.length==0){
													Ext.MessageBox.alert('提示','请选择一条数据');
													}
												else{		
													var message="";                                                  
													for(var i=0;i<selectRows.length;i++){
														if(i!=0){
															message+=",";
															}
														message+=selectRows[i].get(dataId);
														}  
                                                 var _gridBody=Ext.getCmp('grid_'+ExtId).body;   
                                                 _gridBody.mask('查询数据中...');
                                                 Ext.Ajax.request({
																	 url:menuCheckExistUrl,
																	 params:{id:message},																																		 																	success:function(response,option){
																var temp=Ext.util.JSON.decode(response.responseText);                                                  				_gridBody.unmask();
																ds.reload();
																grid.render();
																		 },
																	failure:function(response,option){
                                                                    _gridBody.unmask();
																		var temp=Ext.util.JSON.decode(response.responseText);	                                              						Ext.MessageBox.alert('waring',temp.msg);
																		}
																	 });
													}
}
<?php echo $this->render('link/foot.phtml') ?>
